home *** CD-ROM | disk | FTP | other *** search
- Path: thales.nmia.com!not-for-mail
- From: ghealton@nmia.com (Gilbert Healton)
- Newsgroups: comp.lang.c++
- Subject: \\ question fo iostream people //
- Date: 22 Mar 1996 00:57:57 GMT
- Organization: New Mexico Internet Access
- Message-ID: <4istul$jon@thales.nmia.com>
- NNTP-Posting-Host: socrates.nmia.com
- X-Newsreader: TIN [UNIX 1.3 950515BETA PL0]
-
- How many good ways are there to solve this problem (I am looking for one):
-
- Set up some type of I/O stream (or stream reference and stream) that
- allows a program to write to either standard out or a selected file.
- The ability to switch at will at different points of the program is
- vital. Code that works on different compilers is preferred.
-
- In C the code is simple and portable:
-
- FILE *Stream = (FILE *)NULL;
- char *StreamPath;
- . . .
- if ( SomeCondition )
- { // time to open a file
- if ( Stream ) //but, first, if already open
- fclose( Stream ); ////close the puppy
- if ( *StreamPath )
- Stream = fopen( StreamPath, "w" ); // disk file
- else
- Stream = stdout; // stdout
- }
-
- If I get some good answers, I'll put them in FAQ format and forward them
- to the C++ FAQ.
-
- --
- ----- Computer Consulting / Web Pages ----- http://www.nmia.com/~ghealton/
- These opinions are my own. Life is learning and I may retract, modify,
- even attack, my previous ideas at any time without notice.
-